/**
 * Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.altuure.yagdao.grammar;

import com.altuure.yagdao.grammar.YagdaoParser.result_list_return;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

public class SelectList {
    @Test
    public void test01() throws RecognitionException {
        testResultList( "abc,ttt.dd,count(fff)");
    }
    @Test
    public void test02() throws RecognitionException {
        testResultList( "min(id),max(id),count(fff),avg(xdd)");
    }
    @Test
    public void test03() throws RecognitionException {
        testResultList( "min(id.ddd),max(id),count(fff),avg(xdd)");
    }
    @Test
    public void test04() throws RecognitionException {
        testResultList( "distinct dd");
    }
    @Test
    public void test05() throws RecognitionException {
        testResultList( "month(dd)");
    }
    @Test
    public void test06() throws RecognitionException {
        testResultList( "currentdate()");
    }
    @Test
    public void test07() throws RecognitionException {
        testResultList( "ddds.ddd");
    }
    @Test
    public void test08() throws RecognitionException {
        testResultList( "month(dd)");
    }
    @Test
    public void test09() throws RecognitionException {
        testResultList( "currenttimestamp()");
    }
    @Test
    public void testMathFcuntions() throws RecognitionException {
        testResultList( "neg(sss),abs(ssss),tofloat(sss),tointeger(ss),tolong(22.3),tobigdecimal(222),tobiginteger(222)");
    }
    @Test
    public void testStringFcuntions() throws RecognitionException {
        testResultList( "concat(2232,sss),trim(sss,3,4),lower(aasdas),upper(ssss.sss),length(asdasd),locate(sss,s)");
    }
    @Test
    public void testDate() throws RecognitionException {
        testResultList( "currentDate(),currentTimestamp(),currenttime()");
    }

    /**
     * @param input
     * @throws RecognitionException
     */
    public void testResultList(String input) throws RecognitionException {
        ANTLRStringStream stringStream = new ANTLRStringStream(input);
        final YagdaoLexer lexer = new YagdaoLexer(stringStream);
        YagdaoParser parser = new YagdaoParser(new CommonTokenStream(lexer));

        result_list_return result = parser.result_list();
        System.out.println(input+":");
        System.out.println("\t"+((CommonTree)result.getTree()).toStringTree()+"\n");
        Assert.assertTrue(parser.getErrors().isEmpty());
        List<String> errors = parser.getErrors();
        for (String string : errors) {
            System.err.println("ERROR:"+string);
        }
        Assert.assertTrue(parser.getErrors().isEmpty());
       
     
    }
}
